package com.code.generator.code.impl;

import com.code.config.DataSourceInfo;
import com.code.generator.context.velocity.VelocityGeneratorContext;
import org.springframework.util.StringUtils;

public class MapperXmlGenerator extends AbstractVelocityGenerator {


    public MapperXmlGenerator() {
        super();
    }

    private String subDirName;

    public String getSubDirName() {
        return subDirName;
    }

    public void setSubDirName(String subDirName) {
        this.subDirName = subDirName;
    }

    @Override
    protected String getTemplateName(VelocityGeneratorContext context) {
        return DataSourceInfo.DRIVER_CLASS.getValue() + "/Mapper.xml.vm";
    }

    @Override
    protected String getPackageName(VelocityGeneratorContext context) {
        String xmlDir = "resources.mappers";
        if (!StringUtils.isEmpty(subDirName)) {
            xmlDir = xmlDir + "." + subDirName;
        }
        return xmlDir;
    }

    @Override
    protected String getFileName(VelocityGeneratorContext context) {
        return context.get("entity").toString() + "Mapper.xml";
    }

}
